/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pracamagisterska;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
/**
 *
 * @author Adrian
 */
class Clock {
    javax.swing.Timer time;
    JLabel clock;
    JLabel date;
    Boolean type;

    public Clock(JLabel clock,JLabel date,boolean type) {
        this.clock = clock;
        this.date = date;
        this.type = type;
        time = new javax.swing.Timer(1000, new ClockTickAction());
        time.start();  
    }
    
    public void timeFormatChange(boolean type){
        time.stop();
        this.type=type;
        time = new javax.swing.Timer(1000, new ClockTickAction());
        time.start();        
    }

    private class ClockTickAction implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            DateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
            DateFormat shf;
            if(type) shf = new SimpleDateFormat("HH:mm:ss");
            else shf = new SimpleDateFormat("hh:mm aa");
            Date day = new Date();
            clock.setText(shf.format(day));
            date.setText(sdf.format(day));
            
        }
    }
}